/*
 * @Author: zhang gen yuan
 * @Date: 2021-09-16 17:08:16
 * @Descripttion: 
 */
import router from './router'
import store from './store/index.js'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import getPageTitle from '/@/utils/get-page-title'

NProgress.configure({ showSpinner: false })

const whiteList = [
  '/login',
]
router.beforeEach(async (to, from, next) => {
  NProgress.start()
  document.title = getPageTitle(to.meta.title)
  const hasToken = store.state.user.token;
  if (hasToken) {
    next()
    NProgress.done()
  } else {
    console.log(whiteList.indexOf(to.path) !== -1)
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login`)
      NProgress.done()
    }
  }
})

router.afterEach(() => {
  NProgress.done()
})